package com.burstly.lib.component.networkcomponent.burstly;

import android.app.Activity;
import android.content.Intent;
import android.os.Build.VERSION;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import com.burstly.lib.BurstlySdk;
import com.burstly.lib.component.networkcomponent.IActivityLifeCycleAware;
import com.burstly.lib.component.networkcomponent.burstly.video.VideoFullscreen;
import com.burstly.lib.util.LoggerExt;
import java.lang.ref.Reference;
import java.lang.ref.WeakReference;
import java.util.HashMap;
import java.util.Map;

public class BurstlyFullscreenActivity extends Activity
{
  public static final String BLOCK_BACK_BUTTON = "blockBackButton";
  private static final Map<String, IDecorator> DECORATORS = new HashMap();
  private static final int DEFAULT_BACK_BUTTON_BLOCKING_INTERVAL = 4000;
  public static final String IMPLEMENTATION_ID_KEY = "imlementationIdKey";
  public static final String NETWORK_NAME = "networkName";
  private static final String TAG = "BurstlyFullscreenActivity";
  public static Reference<Activity> sActiveActivity;
  private static volatile boolean sBackButtonEnabled = true;
  private static LoggerExt sLog;
  private View mActivityViewRoot;
  private BackButtonBlocker mBackBtnBlocker;
  private long mBackButtonBlockTime;
  private IFullscreenView mFullscreenView;

  public static IDecorator addDecorator(String paramString, IDecorator paramIDecorator)
  {
    return (IDecorator)DECORATORS.put(paramString, paramIDecorator);
  }

  private void decorate(String paramString)
  {
    if (paramString != null)
    {
      IDecorator localIDecorator = getDecoratorSafe(paramString);
      if (localIDecorator != null)
      {
        View localView = this.mActivityViewRoot;
        this.mActivityViewRoot = localIDecorator.decorate(this.mActivityViewRoot, this);
        if (this.mActivityViewRoot == null)
        {
          sLog.logError("BurstlyFullscreenActivity", "Decorator for {0} returned null after decoration. Original view root will be used.", new Object[] { paramString });
          this.mActivityViewRoot = localView;
        }
      }
      return;
    }
    sLog.logWarning("BurstlyFullscreenActivity", "No network name in intent.", new Object[0]);
  }

  public static IDecorator getDecorator(String paramString)
  {
    return (IDecorator)DECORATORS.get(paramString);
  }

  private IDecorator getDecoratorSafe(String paramString)
  {
    Object localObject = getDecorator(paramString);
    if ((localObject == null) && (this.mFullscreenView.showDefaultCloseButton()))
      localObject = new DefaultInterstitialDecorator(this.mBackButtonBlockTime);
    return localObject;
  }

  private static IFullscreenView getImplementation(Integer paramInteger)
  {
    int i = paramInteger.intValue();
    if (i == ImageFullscreen.IMPLEMENTATION_ID.intValue())
      return new ImageFullscreen();
    if (i == VideoFullscreen.IMPLEMENTATION_ID.intValue())
      return new VideoFullscreen();
    return null;
  }

  private boolean handledByFullscreen(int paramInt, KeyEvent paramKeyEvent)
  {
    return (this.mFullscreenView != null) && (this.mFullscreenView.onKey(this, paramInt, paramKeyEvent));
  }

  public static boolean isBackButtonEnabled()
  {
    return sBackButtonEnabled;
  }

  public static IDecorator removeDecorator(String paramString)
  {
    return (IDecorator)DECORATORS.remove(paramString);
  }

  public static void setBackButtonEnabled(boolean paramBoolean)
  {
    sBackButtonEnabled = paramBoolean;
  }

  private void setContentView(ViewGroup.LayoutParams paramLayoutParams)
  {
    if (paramLayoutParams == null)
    {
      setContentView(this.mActivityViewRoot);
      return;
    }
    setContentView(this.mActivityViewRoot, paramLayoutParams);
  }

  private boolean suppressBackKey(int paramInt)
  {
    if (((paramInt == 4) && (!sBackButtonEnabled)) || ((this.mBackBtnBlocker != null) && (this.mBackBtnBlocker.blocked(paramInt))));
    for (boolean bool = true; ; bool = false)
    {
      if (bool)
        sLog.logDebug("BurstlyFullscreenActivity", "Back button suppressed.", new Object[0]);
      return bool;
    }
  }

  protected void onCreate(Bundle paramBundle)
  {
    getWindow().setFlags(512, 512);
    super.onCreate(paramBundle);
    sActiveActivity = new WeakReference(this);
    BurstlySdk.init(this);
    if (sLog == null)
      sLog = LoggerExt.getInstance();
    if (Build.VERSION.SDK_INT >= 11)
      getWindow().setFlags(16777216, 16777216);
    Intent localIntent = getIntent();
    if (localIntent == null)
    {
      sLog.logError("BurstlyFullscreenActivity", "Current intent is null. Exiting...", new Object[0]);
      finish();
      return;
    }
    this.mBackButtonBlockTime = localIntent.getIntExtra("blockBackButton", 4000);
    if (this.mBackButtonBlockTime < 0L);
    String str;
    for (long l = 4000L; ; l = this.mBackButtonBlockTime)
    {
      this.mBackButtonBlockTime = l;
      this.mBackBtnBlocker = new BackButtonBlocker(this.mBackButtonBlockTime);
      this.mBackBtnBlocker.startBlocking();
      str = localIntent.getStringExtra("networkName");
      Integer localInteger = Integer.valueOf(localIntent.getIntExtra("imlementationIdKey", -1));
      this.mFullscreenView = getImplementation(localInteger);
      if (this.mFullscreenView != null)
        break;
      sLog.logError("BurstlyFullscreenActivity", "Unsupported implementation id: {0}", new Object[] { localInteger });
      finish();
      return;
    }
    ViewGroup.LayoutParams localLayoutParams = this.mFullscreenView.getAttachParameters();
    this.mActivityViewRoot = this.mFullscreenView.onCreate(paramBundle, this);
    if (this.mActivityViewRoot == null)
    {
      finish();
      return;
    }
    decorate(str);
    setContentView(localLayoutParams);
  }

  protected void onDestroy()
  {
    if (this.mFullscreenView != null)
      this.mFullscreenView.onDestroy(this);
    sActiveActivity = null;
    super.onDestroy();
  }

  public boolean onKeyDown(int paramInt, KeyEvent paramKeyEvent)
  {
    if ((suppressBackKey(paramInt)) || (handledByFullscreen(paramInt, paramKeyEvent)));
    for (int i = 1; ; i = 0)
    {
      boolean bool1;
      if (i == 0)
      {
        boolean bool2 = super.onKeyDown(paramInt, paramKeyEvent);
        bool1 = false;
        if (!bool2);
      }
      else
      {
        bool1 = true;
      }
      return bool1;
    }
  }

  protected void onPause()
  {
    if (this.mFullscreenView != null)
      this.mFullscreenView.onPause(this);
    super.onPause();
  }

  protected void onResume()
  {
    if (this.mFullscreenView != null)
      this.mFullscreenView.onResume(this);
    super.onResume();
  }

  public boolean onTouchEvent(MotionEvent paramMotionEvent)
  {
    if ((this.mFullscreenView != null) && (this.mFullscreenView.onTouchEvent(this, paramMotionEvent)))
      return true;
    return super.onTouchEvent(paramMotionEvent);
  }

  public static abstract interface IDecorator
  {
    public abstract View decorate(View paramView, Activity paramActivity);

    public abstract View decorate(View paramView, IOverlayContainer paramIOverlayContainer);
  }

  public static abstract interface IFullscreenView extends IActivityLifeCycleAware
  {
    public abstract ViewGroup.LayoutParams getAttachParameters();

    public abstract View onCreate(Bundle paramBundle, Activity paramActivity);

    public abstract boolean onTouchEvent(Activity paramActivity, MotionEvent paramMotionEvent);

    public abstract boolean showDefaultCloseButton();
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.burstly.lib.component.networkcomponent.burstly.BurstlyFullscreenActivity
 * JD-Core Version:    0.6.2
 */